package com.manualtrader.frame;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractCellEditor;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;

public class TableButtonRenderer extends AbstractCellEditor implements
		TableCellRenderer, TableCellEditor {

	private JButton renderButton = new JButton();

	private JButton editButton = new JButton();

	private String text = null;

	public TableButtonRenderer(String text) {
		this.text = text;

		renderButton.setText(text);
		renderButton.setFont(UIManager.getFont("Table.font"));
		renderButton.setBorder(BorderFactory.createCompoundBorder());

		editButton.setFocusPainted(false);
		editButton.setText(text);
		editButton.setFont(UIManager.getFont("Table.font"));
		editButton.setBorder(BorderFactory.createCompoundBorder());
		
		/*editButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				System.out.println("CLOSE POSITION");
			}
		});*/
		
	}

	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		if (hasFocus) {
			renderButton.setForeground(table.getForeground());
			renderButton.setBackground(UIManager.getColor("Button.background"));
		} else if (isSelected) {
			renderButton.setForeground(table.getSelectionForeground());
			renderButton.setBackground(table.getSelectionBackground());
		} else {
			renderButton.setForeground(table.getForeground());
			renderButton.setBackground(UIManager.getColor("Button.background"));
		}

		return renderButton;
	}

	public Component getTableCellEditorComponent(JTable table, Object value,
			boolean isSelected, int row, int column) {
		return editButton;
	}

	public Object getCellEditorValue() {
		return text;
	}
	
	

}
